TransForm onSubmit Event BuilderSend to SQL Database

Description

Saves the submitted Form data to a SQL database.

Discussion

The Send to SQL Database action inserts submitted Form data into a table in a SQL database.

If the Form has Data Groups, the data from the Form is inserted into multiple tables. Each Data Group's data is inserted into its own table.

The SQL database where data is stored must be accessible from TransForm, which runs on Amazon Web Services. If your SQL database is behind a firewall, you may need to open your firewall to allow access to your database.

If your SQL database does not have any tables for storing the Form data, you can create the tables while configuring the Send to SQL Database action.

Configuring the Send to SQL Database Action

The Send to SQL Database Action Editor
The Send to SQL Database Action Editor

The following properties are used to configure the Send to SQL Database action.

  • General Properties

    Property
    Description
    TransForm Form Name

    The Form Type that is being sent to the SQL database.

    Condition

    Determines when the onSubmit action should be run.

    Your code must set the value of a variable called result to true or false. If true, the submitted Form data will be saved to the SQL database. If false, the Form's data will not be saved. For example:

    Setting the result variable
    var result =  true;

    The next example demonstrates how to save Form data only when the metadata status field is set to 'closed':

    Checking the metadata status field to determine if Form data should be saved to a SQL database
    if (metadata.status.toLowerCase() == 'closed') {
        var result = true;
    } else {
        var result = false;
    }

    The code you define for the Condition can reference data in the submitted Form using the formdata and metadata variables.

    Prefix
    Description
    formdata

    A JavaScript object that contains the Form data submitted. You can use the Insert TransForm form field tool to insert a Form data field into your code if you have loaded sample Form data.

    metadata

    A JavaScript object that contains the meta data for the submitted Form. You can use the Insert TransForm form field tool to insert one of the following metadata variables into your code if you have loaded sample Form data:

    accountid

    The TransForm account ID associated with the Form.

    formid

    The Form Type ID of the Form.

    forminstanceid

    The unique instance ID of the Form.

    status

    The current status of the Form.

    person

    The User ID of the person assigned the Form instance.

    created

    The date/time the Form was created.

    completed

    The date/time when the Form's status was last changed.

    timestamp

    The date/time of when the Form was last inserted or updated in the server database.

    comments

    The representation of the JSON for the comments associated with the Form instance.

    nofiller

    Whether or not the Form should be downloaded to the filler application.

    duedate

    The value of the field in a Form instance that may be used to specify a date. It will either be blank or contain a date formatted as "yyyy-mm-dd". For example, "2024-04-16".

    user1, user2, user3, user4, user5, userlabel1, userlabel2, userlabel3, userlabel4, userlabel5

    The value of the extra fields in a Form instance reserved for use by the TransForm account's administrator.

    Description

    An optional description for the action. Shown in the onSubmit Actions list in TransForm Central.

    SQL database connection string

    A connection string that defines how to connect to your SQL database. Your database must be accessible from Alpha TransForm. If your database is behind a firewall, you will need to allow traffic from TransForm through your firewall. The TransForm egress IP addresses are:

    34.205.230.67
    52.0.35.58
    52.21.232.175

    You will need to make sure your firewall allows traffic to pass through from TransForm's egress IP address.

  • Table and Field Map Settings

    Property
    Description
    Table map

    Defines how the submitted Form data maps to tables in your SQL database.

    The Data Group called <top> represents the top level data in the Form. Top level data is all fields that are not inside a Data Group, including the Form's metadata information.

    If your SQL database does not have existing tables into which you want to insert the Form data, you can click the Create SQL Tables button to automatically create tables in your SQL database.

    Field map

    Defines a field-column mapping between your Form data and table(s) in your SQL database. The Field Map is a CR-LF delimited string using the format "formFieldName=tableColumnName". If the table contains a column of the same name, you can leave the right-hand side of the equals blank.

    For example, the following Field Map maps the fields in an Equipment Inspection Form to a table in a SQL database:

    eqId=equipmentId
    eqType=equipmentType
    isWorking=
    location=siteLocation
    photo=
    inspector=signature

    In the above example, "isWorking" and "photo" have been left blank. This is because the target table has a column named "isWorking" and "photo". For all other Form fields, the target table does not use identical column names, so the mapping must be specified.

    If all fields in the Form Type map to columns of the same name in the target SQL table, you do not need to define a Field Map.

    Field in form data with primary key value

    The field in the Form data that contains the Form's Form Instance ID (i.e. the Form's primary key). If you set this to <Default>, it will be set to '__primaryKey'.

    Field in top level table for the form's forminstanceId

    This is the column in the top level SQL table where the Form's Form Instance ID value will be saved. If you set this to <Default>, it will be set to 'forminstanceid'. You only need to set this value if the table does not contain a column of the same name (i.e. 'forminstanceid').